package com.connection;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ConnectionFactory {
	public static final String connectionString = "jdbc:mysql://localhost:3306/Db_NoticeBoard";
	public static final String userId = "root";
	public static final String password = "a";
	public static Connection con = null;
	
	public static Connection getConnection(){
		try
		{
			Class.forName("com.mysql.jdbc.Driver");
		}		
		
		catch (ClassNotFoundException e)
		{
			e.printStackTrace();
		}
						
		try
		{
			con = DriverManager.getConnection(connectionString, userId,
					password);
		}
		catch (SQLException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return con;
	}
	
	public static boolean closeConnection(){
		if(con!=null)
		{
			try {
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return false;
			}			
		}
		return true;
	}

}
